#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    string s;
    getline(cin, s);

    map<string, int> numbers = {
        {"zero", 0},
        {"one", 1},
        {"two", 2},
        {"three", 3},
        {"four", 4},
        {"five", 5},
        {"six", 6},
        {"seven", 7},
        {"eight", 8},
        {"nine", 9}
    };

    vector<string> s_arr;
    string temp;
    
    for (char c : s) {
        if (c == ' ') {
            if (!temp.empty()) {
                s_arr.push_back(temp);
                temp.clear();
            }
        } else {
            temp += c;
        }
    }
    
    if (!temp.empty()) {
        s_arr.push_back(temp);
    }

    string num_s;

    if (s_arr.size() == 3) {
        for (const auto &word : s_arr) {
            if (numbers.find(word) != numbers.end()) {
                num_s += to_string(numbers[word]);
            } else {
                cout << "Wrong input" << endl;
                return 0;
            }
        }

        int k = stoi(num_s);
        int n = 1000;
        vector<bool> sieve(n, true);
        vector<int> primes;
        
        for (int p = 2; p < n; ++p) {
            if (sieve[p]) {
                primes.push_back(p);
                for (int i = p * p; i < n; i += p) {
                    sieve[i] = false;
                }
            }
        }

        auto it = min_element(primes.begin(), primes.end(), 
                              [k](int a, int b) { return abs(a - k) < abs(b - k); });
        cout << *it << endl;
    } else {
        cout << "Wrong input" << endl;
    }

    return 0;
}
